
//*     "/rmmsg msgid": Remove the message with msgid from the buffer, 
//      and then broadcast to others the following message. 
//      Student1> /rmmsg 101 
//      Student1 removes the msg '101'. 
package server;
import java.net.*;
import java.io.*;
import java.util.*;


class rmmsg extends ChatFormat
{
	public rmmsg(String line)
	{
		super(line);
	}

	public void execute(KKMultiServerThread server)
	{
		//int new_id = server.add_msg_queue(msg);
		try{
			server.rm_msg_queue(  Integer.parseInt(msg) );
		}catch(NoSuchMsgItemException e){
				String name = server.getUser();	
				PrintWriter out = ((KKMultiServerThread.ChatIO) KKMultiServerThread.getChatMap().get(name)).out;
				out.println( msg + " is not exist in the Message Queue");
		}
		
		Set set = KKMultiServerThread.getChatMap().entrySet();
		Iterator It = set.iterator();
		
		int n=0;
		while (It.hasNext()) {
			Map.Entry me = (Map.Entry)It.next();
			PrintWriter out = ( (KKMultiServerThread.ChatIO) me.getValue() ).out;
			String name = server.getUser();
			//Student1 removes the msg '101'. 
			//out.println(name + " removes the msg '" + msg + "'.");
			server.send_reply_client(out, name + " removes the msg '" + msg + "'." );
		}

	}
}
